import json
import os
import csv
l=[]
nl=[]
vu=0
nvu=0
hts=[]
for name in os.listdir('D:\\Work\\Tool\\tiktok\\TikToks\\'):
    if not name.endswith('.json'):
        continue
    if not name.startswith('Hashtag'):
        continue
    with open('D:\\Work\\Tool\\tiktok\\TikToks\\' +name, 'r', encoding='utf-8', newline='\n') as filename_input:
        if name.split('_')[1] not in hts:
            hts.append(name.split('_')[1])
        print(len(hts),name.split('_')[1],len(l),':',len(nl))
        for line in filename_input:
            try:
                z = json.loads(line)
                if 'id' in z.keys():
                    if 'author' not in z.keys():
                        print(name)
                        continue
                    if z['author']['verified']==True or z['author']['verified']=='True' or z['author']['verified']=='true':
                        if z['author']['uniqueId'] not in l:
                            l.append(z['author']['uniqueId'])
                    else:
                        if z['author']['uniqueId'] not in nl:
                            nl.append(z['author']['uniqueId'])
                elif 'itemInfos' in z.keys():
                    if z['authorInfos']['verified']==True or z['authorInfos']['verified']=='True' or z['authorInfos']['verified']=='true':
                        if z['authorInfos']['uniqueId'] not in l:
                            l.append(z['authorInfos']['uniqueId'])
                    else:
                        if z['authorInfos']['uniqueId'] not in nl:
                            nl.append(z['authorInfos']['uniqueId'])
            except:
                print(name,'error')
# with open('D:\\Work\\kusuri\\verified.csv', 'w', encoding='utf-8',newline='\n') as filename_output:
#     writer = csv.writer(filename_output)
#     writer.writerow(l)
#     print(len(l))
